//package com.yunxin.core.domain.service.order.impl;
//
//import com.baomidou.dynamic.datasource.annotation.DS;
//import com.yunxin.common.exception.BusinessException;
//import com.yunxin.core.domain.model.order.*;
//import com.yunxin.core.infra.common.order.enums.OrderAllocationStatusEnum;
//import com.yunxin.core.infra.common.order.enums.OrderAllocationTypeEnum;
//import com.yunxin.core.utils.infra.common.constant.CoreResultCode;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//
//import java.util.*;
//
///**
// * @author zero°
// * @since 2023-06-03
// */
//@DS("core")
//@Slf4j
//@Component
//@RequiredArgsConstructor
//public class OrderUserApplyAllocationHandle {
//
//
//    private final OrderUserApplyRepository orderUserApplyRepository;
//
//    private final OrderUserApplyDetailRepository orderUserApplyDetailRepository;
//
//    private final OrderUserApplyAllocationRepository orderUserApplyAllocationRepository;
//
//    private final OrderUserAllocationMatchHandle orderUserAllocationMatchHandle;
//
//    /**
//     * 分配用户订单
//     * @param applyOrderNo applyOrderNo
//     * @param clientIp clientIp
//     * @return AllocationOrderUserApplyResultDTO
//     */
//    public AllocationOrderUserApplyResult allocationOrderUserApply(String applyOrderNo, String clientIp) {
//        OrderUserApply userApply = orderUserApplyRepository.getOrderUserApplyByApplyOrderNo(applyOrderNo);
//        if (Objects.isNull(userApply)) {
//            throw new BusinessException(CoreResultCode.ORDER_USER_APPLY_NOT_EXIST);
//        }
//        //查询是否已分配
//        if (!OrderAllocationStatusEnum.UN_ALLOCATION.getValue().equals(userApply.getAllocationStatus())) {
//            OrderUserApplyAllocation orderUserApplyAllocation = orderUserApplyAllocationRepository.getByApplyOrderNoAndAllocationTypes(applyOrderNo,
//                    List.of(OrderAllocationTypeEnum.ALLOCATION_AUTOMATIC.getValue(), OrderAllocationTypeEnum.ALLOCATION_RULE.getValue()));
//            AllocationOrderUserApplyResult resultDTO = new AllocationOrderUserApplyResult();
//            resultDTO.setAllocationOrderId(orderUserApplyAllocation.getId());
//            resultDTO.setProductId(orderUserApplyAllocation.getProductId());
//            resultDTO.setIsBottom(1);
//            return resultDTO;
//        }
//        OrderUserApplyDetail applyDetail = orderUserApplyDetailRepository.getOrderUserApplyDetailByApplyOrderNo(userApply.getApplyOrderNo());
//        //订单分配
//        return orderUserAllocationMatchHandle.orderAllocation(userApply, applyDetail, clientIp);
//    }
//}
